#pragma once
#include "Entity.h"
#include "Light.h"

namespace Core{
	class ScriptManager;
}

namespace Graphics{
	class RenderSystem;

	class SceneManager : public Core::MemTrack{
	public:
		SceneManager(){}
		virtual ~SceneManager(){}
		
		typedef std::map<unsigned int, std::list<unsigned int>> RenderIdList;

		virtual void render(RenderContext *context) = 0;
		virtual unsigned int addEntity(EntityPtr entity) = 0;
		virtual void removeEntity(unsigned int id) = 0;

		virtual EntityPtr getEntity(unsigned int id) = 0;

	protected:
		void setRenderSystem(RenderSystem* renderSystem) { m_renderSystem = renderSystem; }

		// Lua wrappers
		int addMesh_luaWrap(LuaPlus::LuaObject modelId);
		void removeMesh_luaWrap(LuaPlus::LuaObject meshId);
		LuaPlus::LuaObject getMesh_luaWrap(LuaPlus::LuaObject meshId);

		void purgeLuaState(LuaPlus::LuaState* state);

		boost::shared_ptr<Core::EventConnection> m_connection;
		RenderIdList m_renderObjects;
		RenderSystem *m_renderSystem;

		std::map<LuaPlus::LuaState*,std::set<int>> m_luaStateMeshes;

		friend class RenderSystem;
		friend class DX11RenderSystem;
		friend class DX10RenderSystem;
		friend class DX9RenderSystem;
		friend class Core::ScriptManager;
	};
}

typedef boost::shared_ptr<Graphics::SceneManager> SceneManagerPtr;